package projects.defaultProject.models.energyConsumptionModels;

import sinalgo.models.EnergyConsumptionModel;
import sinalgo.nodes.Node;
import sinalgo.nodes.messages.Message;

public class TxRxConsumptionModel extends EnergyConsumptionModel {
	public TxRxConsumptionModel() {
		super();
	}

	@Override
	public void messageSent(Node node, Message message, double intensity) {
		node.setEnergyLevel(node.getEnergyLevel() - intensity * joulesPerByteTx
				* message.getMessageSize() < 0 ? 0 : node.getEnergyLevel()
				- intensity * joulesPerByteTx * message.getMessageSize());
	}

	@Override
	public void enabledStep(Node node) {

	}

	@Override
	public boolean hasEnergyToAck(Node node, Message message, double intensity) {
		return true;
	}

	@Override
	public boolean hasEnergyToReceive(Node node, Message message,
			double intensity) {
		return node.getEnergyLevel() > joulesPerByteRx
				* message.getMessageSize();
	}

	@Override
	public boolean hasEnergyToSend(Node node, Message message, double intensity) {
		return node.getEnergyLevel() > joulesPerByteTx
				* message.getMessageSize();
	}

	@Override
	public void messageAcked(Node node, Message message, double intensity) {
	}

	@Override
	public void messageReceived(Node node, Message message) {
		node.setEnergyLevel(node.getEnergyLevel() - joulesPerByteRx
				* message.getMessageSize() < 0 ? 0 : node.getEnergyLevel()
				- joulesPerByteRx * message.getMessageSize());
	}

	@Override
	public void standByStep(Node node) {
		// TODO Auto-generated method stub

	}
}
